home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 14967 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: GIMLI.genias.de!usenet
  2. From: Andreas Haas <andreas>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: 2d array of pointers to structures ?
  5. Date: 16 Apr 1996 12:34:01 GMT
  6. Organization: GENIAS Software GmbH
  7. Message-ID: <4l043p$b05@GIMLI.genias.de>
  8. References: <829573448snz@willen.demon.co.uk>
  9. NNTP-Posting-Host: balin.genias.de
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 1.1N (X11; I; SunOS 4.1.2 sun4c)
  14. X-URL: news:829573448snz@willen.demon.co.uk
  15.  
  16. Adrian Parker <adrian@willen.demon.co.uk> wrote:
  17. >
  18. >I need to keep a 2d array of structures, which I have to do at runtime 
  19. >as they array could be quite big, and the compiler can't cope with 
  20. >static arrays of the required size.
  21. >
  22.  
  23. Try this:
  24.  
  25. T_loc **lpp = NULL;
  26.  
  27. lpp = (T_loc **)malloc(cols*sizeof(T_loc *));
  28. for (i=0; i<rows; i++)
  29.    lpp[i] = (T_loc *)malloc(rows*sizeof(T_loc));
  30.  
  31.  
  32. now you can access these entries as follows:
  33.  
  34. lpp[i][j].id     = 0;
  35. lpp[i][j].colour = GREEN;
  36.  
  37. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  38.                         Andreas Haas
  39. GENIAS Software GmbH             | Email:  andreas@genias.de
  40. Erzgebirgstr. 2 B                | Tel.:   ++49 +9401 9200-0/41
  41. D-93073 Neutraubling/Germany     | FAX:    ++49 +9401 9200-92
  42. http://www.genias.de/            |
  43. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  44.  
  45.